package io.github.uicdb.et.item;

import io.github.uicdb.et.item_data.ItemElementData;
import io.github.uicdb.et.ModItemDataComponents;
import io.github.uicdb.et.element.BasicElement;
import io.github.uicdb.et.register.ElementalObject;
import io.github.uicdb.et.register.IElementalGetter;
import net.minecraft.core.Holder;
import net.minecraft.stats.Stats;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;

public class ElementCrystalBlockItem extends Item implements IElementalGetter {

    public ElementCrystalBlockItem(Properties properties, Holder<BasicElement> element, int amount, int ticks) {
        super(
                properties.stacksTo(1).component(ModItemDataComponents.ITEM_ELEMENT_DATA, new ItemElementData(
                        element, amount, ticks)
                ));

    }


    @Override
    public boolean onLeftClickEntity(@NotNull ItemStack stack, Player player, @NotNull Entity entity) {
        if (!player.isCreative()) stack.shrink(1);
        player.awardStat(Stats.ITEM_USED.get(this));
        return super.onLeftClickEntity(stack, player, entity);
    }


    ElementalObject elementalTheory$elementalObject;

    @Override
    public ElementalObject getElementalObject() {
        return elementalTheory$elementalObject;
    }

    @Override
    public void setElementalObject(ElementalObject elementalObject) {
        this.elementalTheory$elementalObject = elementalObject;
    }
}
